package com.qf.fmall.utils;

import com.github.wxpay.sdk.WXPay;
import com.qf.fmall.config.PayConfig;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 王权富贵
 */
public class WxpayUtils {

    public static String getPayUrl(String orderId) throws Exception {
        Map<String, String> data = new HashMap<>();
        data.put("body", "testproduct");  //商品描述
        data.put("out_trade_no", orderId);               //使用当前用户订单的编号作为当前支付交易的交易号
        data.put("fee_type", "CNY");                     //支付币种
        data.put("total_fee", "1");
        data.put("trade_type", "NATIVE");                //交易类型
        data.put("notify_url", "http://47.118.45.73:8080/pay/callback");           //设置支付完成时的回调方法接口

        //发送请求，获取响应
        //微信支付：申请支付连接
        WXPay wxPay = new WXPay(new PayConfig());
        Map<String, String> resp = wxPay.unifiedOrder(data);
        return resp.get("code_url");
    }
    public static String queryOrder(String orderId) throws Exception {
        HashMap<String, String> params = new HashMap<>();
        params.put("out_trade_no", orderId);
        WXPay wxPay = new WXPay(new PayConfig());
        Map<String, String> resp = wxPay.orderQuery(params);
        return resp.get("trade_state");
    }
}
